﻿using Microsoft.EntityFrameworkCore.Migrations;
using Microsoft.EntityFrameworkCore;
using Common.Configurations;

namespace Common.EfCore;

public static class DbContextOptionsBuilderExtensions
{
    public static DbContextOptionsBuilder UseRemoveForeignKeyService(
        this DbContextOptionsBuilder options, 
        DatabaseSettings settings)
    {
        if (!settings.EnableForeignKeys)
        {
            switch (settings.DBProvider.ToLower())
            {
                case "sqlite":
                    options.ReplaceService<IMigrationsSqlGenerator, CustomSqliteMigrationsSqlGenerator>();
                    break;
                case "mysql":
                    options.ReplaceService<IMigrationsSqlGenerator, CustomMySqlMigrationsSqlGenerator>();
                    break;
                case "mssql":
                    options.ReplaceService<IMigrationsSqlGenerator, CustomSqlServerMigrationsSqlGenerator>();
                    break;
                case "postgresql":
                    options.ReplaceService<IMigrationsSqlGenerator, CustomNpgsqlMigrationsSqlGenerator>();
                    break;
                default:
                    break;
            }
        }
        return options;
    }
}
